package com.curry.cloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/provider")
@Slf4j
public class providerController {

    @GetMapping("/getValue/{num}")
    public Map getValue(@PathVariable Long num){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("value",num+"-123456");
        map.put("code",200);
        map.put("message","success");
        int n = 1/0;
        return map;
    }

/*    //超时降级演示
    @HystrixCommand(fallbackMethod = "sleep_TimeoutHandler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="3000") //5秒钟以内就是正常的业务逻辑
    })*/


    @GetMapping("sleep")
    public String sleep(){

        log.info("start");

        try {
            TimeUnit.MILLISECONDS.sleep(850);
//            TimeUnit.SECONDS.sleep(6);
        } catch (Exception e) {
            e.printStackTrace();
        } //单位秒

        log.info("end");
        return "stop sleep !";

    }


/*    //兜底方法，上面方法出问题,我来处理，返回一个出错信息
    public String sleep_TimeoutHandler() {
        return "线程池："+Thread.currentThread().getName()+" sleep_TimeoutHandler,系统繁忙,请稍后再试\t o(╥﹏╥)o ";
    }*/

}
